{include file="Public:header2"/}
<body style="min-height: 100%;background-color: #fff">

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form onsubmit="return false;">
                        <div class="layui-form" wid100 lay-filter="">
                            <div class="layui-form-item" >
                                <label class="layui-form-label">抽卡机分类</label>
                                <div class="layui-input-inline" style="width: 600px">
                                    <select name="category_id" >
                                        <option  value="">--请选择--</option>
                                        {foreach name="category" item="vo"}
                                        <option value="{$vo.id}">{$vo.title}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">盒子名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" placeholder="请输入盒子名称" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">盒子简介</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="card_notice" placeholder="请输入盒子简介" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">盒子价格</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="price" placeholder="请输入盒子价格" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">显示价格</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="show_price" placeholder="请输入显示价格" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">张数</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="card_num" placeholder="请输入一包几张卡片" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">排序值</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="sort" value="0" placeholder="请输入排序值" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item coupon_is">
                                <label class="layui-form-label">发券开关</label>
                                <div class="layui-input-inline"  style="width: 600px">
                                    <input type="radio" name="coupon_is" value="1" class="layui-input" title="开启" >
                                    <input type="radio" name="coupon_is" value="0" class="layui-input" title="关闭" checked>
                                </div>
                            </div>
                            <div class="layui-form-item coupon_pro">
                                <label class="layui-form-label">发券概率</label>
                                <div class="layui-input-inline"  style="width: 600px">
                                    <input type="text" name="coupon_pro" value="0"  placeholder="请输入发券概率" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item integral_is" style="display:none">
                                <label class="layui-form-label">发积分开关</label>
                                <div class="layui-input-inline"  style="width: 600px">
                                    <input type="radio" name="integral_is" value="1" class="layui-input" title="开启" >
                                    <input type="radio" name="integral_is" value="0" class="layui-input" title="关闭" checked>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">盒子封面图</label>
                                <div class="layui-input-inline">
                                    <input type="hidden" name="imgurl" value="" lay-verify="required" placeholder="请上传图片" autocomplete="off" class="layui-input" >
                                    <img style="float:left;width:120px;" class="" id="imgurl" src="/static/image/upload.jpg">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">盒子详情图</label>
                                <div class="layui-input-inline">
                                    <input type="hidden" name="imgurl_detail" value="" lay-verify="required" placeholder="请上传图片" autocomplete="off" class="layui-input" >
                                    <img style="float:left;width:120px;" class="" id="imgurl_detail" src="/static/image/upload.jpg">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">卡牌背面图</label>
                                <div class="layui-input-inline">
                                    <input type="hidden" name="prize_imgurl" value="" lay-verify="required" placeholder="请上传图片" autocomplete="off" class="layui-input" >
                                    <img style="float:left;width:120px;" class="" id="prize_imgurl" src="/static/image/upload.jpg">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">卡册banner</label>
                                <div class="layui-input-inline">
                                    <input type="hidden" name="card_banner" value="" lay-verify="required" placeholder="请上传图片" autocomplete="off" class="layui-input" >
                                    <img style="float:left;width:120px;" class="" id="card_banner" src="/static/image/upload.jpg">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" onclick="return check()">确认保存</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="Public:footer"/}
</body>
</html>
<script type="text/javascript">
    layui.use(['layer','form','upload','laydate'], function(){
        var $ = layui.$;
        var form = layui.form;
        var upload = layui.upload;
        var laydate = layui.laydate;

        //执行实例
        upload.render({
            accept:'imgurl'
            ,elem: '#imgurl' //绑定元素
            ,url: '/admin/picture' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.status == 1){ //成功
                    layer.msg("上传成功",{icon:1,time:1000},function(){
                        $("#imgurl").attr("src",res.data.path);  //单图
                        $("input[name=imgurl]").val(res.data.imgurl);
                    });
                }else{ //失败
                    layer.msg(res.msg,{icon:2,anim:6,time:1500});
                }
            }
            ,error: function(){
                //请求异常回调
                layer.msg('服务繁忙，请稍后再试',{icon:2,anim:6,time:1500});
            }
        });

        //执行实例
        upload.render({
            accept:'imgurl'
            ,elem: '#imgurl_detail' //绑定元素
            ,url: '/admin/picture' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.status == 1){ //成功
                    layer.msg("上传成功",{icon:1,time:1000},function(){
                        $("#imgurl_detail").attr("src",res.data.path);  //单图
                        $("input[name=imgurl_detail]").val(res.data.imgurl);
                    });
                }else{ //失败
                    layer.msg(res.msg,{icon:2,anim:6,time:1500});
                }
            }
            ,error: function(){
                //请求异常回调
                layer.msg('服务繁忙，请稍后再试',{icon:2,anim:6,time:1500});
            }
        });

        //执行实例
        upload.render({
            accept:'imgurl'
            ,elem: '#prize_imgurl' //绑定元素
            ,url: '/admin/picture' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.status == 1){ //成功
                    layer.msg("上传成功",{icon:1,time:1000},function(){
                        $("#prize_imgurl").attr("src",res.data.path);  //单图
                        $("input[name=prize_imgurl]").val(res.data.imgurl);
                    });
                }else{ //失败
                    layer.msg(res.msg,{icon:2,anim:6,time:1500});
                }
            }
            ,error: function(){
                //请求异常回调
                layer.msg('服务繁忙，请稍后再试',{icon:2,anim:6,time:1500});
            }
        });


        //执行实例
        upload.render({
            accept:'imgurl'
            ,elem: '#card_banner' //绑定元素
            ,url: '/admin/picture' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.status == 1){ //成功
                    layer.msg("上传成功",{icon:1,time:1000},function(){
                        $("#card_banner").attr("src",res.data.path);  //单图
                        $("input[name=card_banner]").val(res.data.imgurl);
                    });
                }else{ //失败
                    layer.msg(res.msg,{icon:2,anim:6,time:1500});
                }
            }
            ,error: function(){
                //请求异常回调
                layer.msg('服务繁忙，请稍后再试',{icon:2,anim:6,time:1500});
            }
        });


    });

    function check(){
        var url="{:url('/admin/card_goods_add')}";
        var $ = layui.$;
        var load=layer.load(2);
        $.post(url,$("form").serialize(),function(data){
            if(data.status==1){
                layer.msg(data.msg,{icon:1,time:1500},function(){
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index);
                    parent.location.reload();
                });
            }else{
                layer.msg(data.msg,{icon:2,anim:6,time:1500},function(){
                    layer.close(load);
                });
            }
        })
    }
</script>
